package com.java2007.service.impl;

import com.java2007.dao.AdminDao;
import com.java2007.factory.BeanFactory;
import com.java2007.pojo.Admin;
import com.java2007.service.AdminService;
import com.java2007.util.MD5Utils;

import java.sql.SQLException;

/**
 * 用户业务实现层
 */
public class AdminServiceImpl implements AdminService {
    private AdminDao adminDao= (AdminDao) BeanFactory.getBean("com.java2007.dao.impl.AdminDaoImpl");
    /**
     * 登录业务
     * @param adminName
     * @param password
     * @return
     */
    @Override
    public Admin login(String adminName, String password) throws SQLException {
        Admin admin = adminDao.selectByUserName(adminName);
        if (admin!=null){
            String finalPassword= MD5Utils.md5(password);
            if (finalPassword.equals(admin.getPassword())){
                return admin;
            }
        }
        return null;
    }

//    public static void main(String[] args) {
//        String password = "0000";
//        String finalPassword= MD5Utils.md5(password);
//        System.out.println(finalPassword);
//    }
}
